package dS.ProjectGPS.LeicaOWI;

import javax.microedition.lcdui.*;

// This class is unfinished

public class FormOwiDCT extends Form implements FormOwi {

  OWIAgent owiAgent = null;

  ChoiceGroup deviceAtPort = new ChoiceGroup("Device At", ChoiceGroup.POPUP);
  TextField deviceName = new TextField("Device Name", "", 30, TextField.ANY);
  ChoiceGroup deviceType = new ChoiceGroup("Device Type", ChoiceGroup.POPUP);
  TextField radioChannel = new TextField("Radio Channel", "", 2, TextField.NUMERIC);

  TextField gsmStationNumber = new TextField("Station Number", "", 20, TextField.NUMERIC);
  ChoiceGroup gsmProtocol = new ChoiceGroup("Device Type", ChoiceGroup.POPUP);
  ChoiceGroup gsmUseCoord = new ChoiceGroup("Use Coord", ChoiceGroup.EXCLUSIVE);
  ChoiceGroup gsmDatumId = new ChoiceGroup("Datum ID", ChoiceGroup.EXCLUSIVE);
  ChoiceGroup gsmCoordType = new ChoiceGroup("Coord Type", ChoiceGroup.POPUP);

  public FormOwiDCT(OWIAgent o) {
    super("Device Control");

    owiAgent = o;

    try {
      ndsInit();
    }
    catch (Exception ex) {
    }
  }

  public void ndsInit() throws Exception {
    append(deviceAtPort);
    deviceAtPort.append("Port 1", null);
    deviceAtPort.append("Port 2", null);
    deviceAtPort.append("Port 3", null);
    deviceAtPort.append("Port 4", null);
    append(deviceName);

    append(deviceType);
    deviceType.append("Radio", null);
    deviceType.append("GSM", null);
    deviceType.append("Modem", null);
    deviceType.append("SAPOS", null);
    deviceType.append("SmartGate", null);

    gsmProtocol.append("Analogue",null);
    gsmProtocol.append("ISDN V.110", null);
    gsmProtocol.append("ISDN V.120", null);

    gsmUseCoord.append("No", null);
    gsmUseCoord.append("Yes", null);

    gsmDatumId.append("WGS84", null);
    gsmDatumId.append("Local", null);

    //gsmCoordType.append("");

  }

  public void update() {
    owiAgent.query(OWI.qsCUT());

    deviceAtPort.setSelectedIndex(OWI.dctUsedAtPort, true);
    deviceName.setString(OWI.dctDeviceName);
    deviceType.setSelectedIndex(OWI.dctDeviceType, true);
    radioChannel.setString(OWI.dctRadioChannelNumber);
    gsmStationNumber.setString(OWI.dctGsmStationNumber);
    gsmProtocol.setSelectedIndex(OWI.dctGsmProtocol, true);


    switch(OWI.dctDeviceType){
      case(1):{ // Radio
        append(radioChannel);
        break;
      }
      case(2):{ // GSM
        append(gsmUseCoord);
        append(gsmProtocol);

        if(Integer.parseInt(OWI.dctGsmUseCoord) == 1){
          append(gsmDatumId);
          //append();
        }
        break;
      }
    }

  }

  public void save() {
    // Setup SET parameters
    /*String[] outputs = {
                       cutoff.getString(),
    };

    //Send message and update form if successful
    if (owiAgent.set("CUT", OWI.setMessage(outputs))) {
      Controller.showAlert(AlertType.CONFIRMATION, this, "", "Save successful.");
      update();
    }
    else {
      Controller.showAlert(AlertType.ERROR, this, "",
                           "Save to sensor unsuccessful.");
    } */
  }

}
